
#include "iostream"
#include "vector"
#include "unordered_map"
#include "algorithm"

class Solution{
public:
};
void print_conv(int a,int jinzhi){
    static char map[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
    std::string s;
    if(a==0){
        printf("0\n");
        return;
    }
    while(a){
        s+=map[a%jinzhi];
        a/=jinzhi;
    }
    for(int i=s.size()-1;i>=0;i--){
        printf("%c",s[i]);
    }
    printf("\n");
}
int main() {
    int a,b;
    while(std::cin>>a>>b){
        print_conv(a,b);
    }
    return 0;
}

